import { ReactNode } from 'react'
import {Navigate, useLocation} from 'react-router-dom'
import { useUserToken } from "@/store/userStore";
import {ROUTE_PATHS} from "@/routs/routes.ts";
interface ProtectedRouteProps {
  children: ReactNode
}

export const ProtectedRoute = ({ children }: ProtectedRouteProps) => {
  const location = useLocation()
  const { token } = useUserToken();

  if (!token) {
    return <Navigate to={ROUTE_PATHS.LOGIN} state={{ from: location }} replace />
  }

  return <>{children}</>
}
